#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Solution {
public:
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
        int m = nums1.size();
        int n = nums2.size();
        vector<int> merged;
        vector<int>::iterator n1it=nums1.begin(), n2it=nums2.begin();
        while (n1it != nums1.end() && n2it != nums2.end()) {
            if (*n1it > *n2it) {
                merged.push_back(*n2it);
                n2it++;
            }
            else{
                merged.push_back(*n1it);
                n1it++;
            }
        }
        while (n1it != nums1.end()) {
            merged.push_back(*n1it);
            n1it++;
        }
        while (n2it != nums2.end()) {
            merged.push_back(*n2it);
            n2it++;
        }
        int mid = merged.size()/2;
        if (merged.size() % 2) {
            return merged[mid];
        }
        else {
            double res = (merged[mid] + merged[mid - 1]) / 2.0;
            return res;
        }
    }
};


int main() {
    vector<int> n1 = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4 };
    vector<int> n2 = { 1, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
    Solution s;
    double res=s.findMedianSortedArrays(n1, n2);
    cout << res << endl;
}